//package com.iot.jurisdiction.filter;
//
//import com.iot.commonutils.utils.JwtUtil;
//import io.jsonwebtoken.Claims;
//import org.apache.commons.lang3.StringUtils;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.stereotype.Component;
//import org.springframework.web.bind.annotation.RequestMapping;
//import org.springframework.web.method.HandlerMethod;
//import org.springframework.web.servlet.HandlerInterceptor;
//
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;
//import java.util.List;
//
///**
// * 过滤器
// */
//@Component
//public class LoginInterceptor implements HandlerInterceptor {
//    private static final Logger log = LoggerFactory.getLogger(LoginInterceptor.class);
//
//    @Override
//    public boolean preHandle(HttpServletRequest request,
//                             HttpServletResponse response,
//                             Object handler) throws Exception {
//        String authorization = request.getHeader("Authorization");
//
//        if (StringUtils.isNotEmpty(authorization) && authorization.startsWith("Bearer")){
//            String token = authorization.replace("Bearer ","");
//
//            Claims claims = JwtUtil.getClaimsBody(token);
//
//            if (claims != null){
//
//                List<String> permissionFlagList = (List<String>)claims.get("permissionFlagList");
//
//                HandlerMethod handlerMethod = (HandlerMethod) handler;
//
//                RequestMapping annotation = handlerMethod.getMethodAnnotation(RequestMapping.class);
//
//                String name = annotation.name();
//
//                if (permissionFlagList.contains(name)){
//                    request.setAttribute("user_claims",claims);
//                    return true;
//                }else {
//                    log.info("没权限老弟");
//                    throw new Exception("没权限老弟");
//                }
//
//            }
//        }
//
//        log.info("token非法");
//        throw new Exception("token非法");
//    }
//}
